#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

void swap(vector<int> &vec, int i, int j)
{
    int tmp = vec[i];
    vec[i] = vec[j];
    vec[j] = tmp;
}

bool judge(vector<int> &vec, int i)
{
    for(int j{}; j < i; j++){
        if(abs(vec[i] - vec[j]) == abs(i - j))
            return false;
    }
    return true;
}

void resolve(vector<int> &vec, int i, int len, int &result)
{

    if (i == len)
    {
        result++;
    }
    else
    {
        for (int j{i}; j < len; j++)
        {
            swap(vec, i, j);
            if (judge(vec, i))
                resolve(vec, i + 1, len, result);
            swap(vec, i, j);
        }
    }
}

int main(int args, char *argv[])
{
    vector<int> vec;
    // 初始化原始数组
    for (int i{}; i < 4; i++)
    {
        vec.push_back(i);
    }
    int result;
    resolve(vec, 0, vec.size(), result);
    
    printf("%d\n", result);

    return result;
}